{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(50, 52, 2647)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sys\n",
    "count = 0\n",
    "for item in dir('a'):\n",
    "    if item[0] != '_':\n",
    "        count += sys.getsizeof(item)\n",
    "sys.getsizeof('a'), sys.getsizeof('abc'),count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"aa'a'\""
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sys\n",
    "a = 'a'\n",
    "'a{}{!r}'.format(a,a,a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on PdfFileReader in module PyPDF2.pdf object:\n",
      "\n",
      "class PdfFileReader(builtins.object)\n",
      " |  PdfFileReader(stream, strict=True, warndest=None, overwriteWarnings=True)\n",
      " |  \n",
      " |  Initializes a PdfFileReader object.  This operation can take some time, as\n",
      " |  the PDF stream's cross-reference tables are read into memory.\n",
      " |  \n",
      " |  :param stream: A File object or an object that supports the standard read\n",
      " |      and seek methods similar to a File object. Could also be a\n",
      " |      string representing a path to a PDF file.\n",
      " |  :param bool strict: Determines whether user should be warned of all\n",
      " |      problems and also causes some correctable problems to be fatal.\n",
      " |      Defaults to ``True``.\n",
      " |  :param warndest: Destination for logging warnings (defaults to\n",
      " |      ``sys.stderr``).\n",
      " |  :param bool overwriteWarnings: Determines whether to override Python's\n",
      " |      ``warnings.py`` module with a custom implementation (defaults to\n",
      " |      ``True``).\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __init__(self, stream, strict=True, warndest=None, overwriteWarnings=True)\n",
      " |      Initialize self.  See help(type(self)) for accurate signature.\n",
      " |  \n",
      " |  cacheGetIndirectObject(self, generation, idnum)\n",
      " |  \n",
      " |  cacheIndirectObject(self, generation, idnum, obj)\n",
      " |  \n",
      " |  decrypt(self, password)\n",
      " |      When using an encrypted / secured PDF file with the PDF Standard\n",
      " |      encryption handler, this function will allow the file to be decrypted.\n",
      " |      It checks the given password against the document's user password and\n",
      " |      owner password, and then stores the resulting decryption key if either\n",
      " |      password is correct.\n",
      " |      \n",
      " |      It does not matter which password was matched.  Both passwords provide\n",
      " |      the correct decryption key that will allow the document to be used with\n",
      " |      this library.\n",
      " |      \n",
      " |      :param str password: The password to match.\n",
      " |      :return: ``0`` if the password failed, ``1`` if the password matched the user\n",
      " |          password, and ``2`` if the password matched the owner password.\n",
      " |      :rtype: int\n",
      " |      :raises NotImplementedError: if document uses an unsupported encryption\n",
      " |          method.\n",
      " |  \n",
      " |  getDestinationPageNumber(self, destination)\n",
      " |      Retrieve page number of a given Destination object\n",
      " |      \n",
      " |      :param Destination destination: The destination to get page number.\n",
      " |           Should be an instance of\n",
      " |           :class:`Destination<PyPDF2.pdf.Destination>`\n",
      " |      :return: the page number or -1 if page not found\n",
      " |      :rtype: int\n",
      " |  \n",
      " |  getDocumentInfo(self)\n",
      " |      Retrieves the PDF file's document information dictionary, if it exists.\n",
      " |      Note that some PDF files use metadata streams instead of docinfo\n",
      " |      dictionaries, and these metadata streams will not be accessed by this\n",
      " |      function.\n",
      " |      \n",
      " |      :return: the document information of this PDF file\n",
      " |      :rtype: :class:`DocumentInformation<pdf.DocumentInformation>` or ``None`` if none exists.\n",
      " |  \n",
      " |  getFields(self, tree=None, retval=None, fileobj=None)\n",
      " |      Extracts field data if this PDF contains interactive form fields.\n",
      " |      The *tree* and *retval* parameters are for recursive use.\n",
      " |      \n",
      " |      :param fileobj: A file object (usually a text file) to write\n",
      " |          a report to on all interactive form fields found.\n",
      " |      :return: A dictionary where each key is a field name, and each\n",
      " |          value is a :class:`Field<PyPDF2.generic.Field>` object. By\n",
      " |          default, the mapping name is used for keys.\n",
      " |      :rtype: dict, or ``None`` if form data could not be located.\n",
      " |  \n",
      " |  getFormTextFields(self)\n",
      " |      Retrieves form fields from the document with textual data (inputs, dropdowns)\n",
      " |  \n",
      " |  getIsEncrypted(self)\n",
      " |  \n",
      " |  getNamedDestinations(self, tree=None, retval=None)\n",
      " |      Retrieves the named destinations present in the document.\n",
      " |      \n",
      " |      :return: a dictionary which maps names to\n",
      " |          :class:`Destinations<PyPDF2.generic.Destination>`.\n",
      " |      :rtype: dict\n",
      " |  \n",
      " |  getNumPages(self)\n",
      " |      Calculates the number of pages in this PDF file.\n",
      " |      \n",
      " |      :return: number of pages\n",
      " |      :rtype: int\n",
      " |      :raises PdfReadError: if file is encrypted and restrictions prevent\n",
      " |          this action.\n",
      " |  \n",
      " |  getObject(self, indirectReference)\n",
      " |  \n",
      " |  getOutlines(self, node=None, outlines=None)\n",
      " |      Retrieves the document outline present in the document.\n",
      " |      \n",
      " |      :return: a nested list of :class:`Destinations<PyPDF2.generic.Destination>`.\n",
      " |  \n",
      " |  getPage(self, pageNumber)\n",
      " |      Retrieves a page by number from this PDF file.\n",
      " |      \n",
      " |      :param int pageNumber: The page number to retrieve\n",
      " |          (pages begin at zero)\n",
      " |      :return: a :class:`PageObject<pdf.PageObject>` instance.\n",
      " |      :rtype: :class:`PageObject<pdf.PageObject>`\n",
      " |  \n",
      " |  getPageLayout(self)\n",
      " |      Get the page layout.\n",
      " |      See :meth:`setPageLayout()<PdfFileWriter.setPageLayout>`\n",
      " |      for a description of valid layouts.\n",
      " |      \n",
      " |      :return: Page layout currently being used.\n",
      " |      :rtype: ``str``, ``None`` if not specified\n",
      " |  \n",
      " |  getPageMode(self)\n",
      " |      Get the page mode.\n",
      " |      See :meth:`setPageMode()<PdfFileWriter.setPageMode>`\n",
      " |      for a description of valid modes.\n",
      " |      \n",
      " |      :return: Page mode currently being used.\n",
      " |      :rtype: ``str``, ``None`` if not specified\n",
      " |  \n",
      " |  getPageNumber(self, page)\n",
      " |      Retrieve page number of a given PageObject\n",
      " |      \n",
      " |      :param PageObject page: The page to get page number. Should be\n",
      " |          an instance of :class:`PageObject<PyPDF2.pdf.PageObject>`\n",
      " |      :return: the page number or -1 if page not found\n",
      " |      :rtype: int\n",
      " |  \n",
      " |  getXmpMetadata(self)\n",
      " |      Retrieves XMP (Extensible Metadata Platform) data from the PDF document\n",
      " |      root.\n",
      " |      \n",
      " |      :return: a :class:`XmpInformation<xmp.XmpInformation>`\n",
      " |          instance that can be used to access XMP metadata from the document.\n",
      " |      :rtype: :class:`XmpInformation<xmp.XmpInformation>` or\n",
      " |          ``None`` if no metadata was found on the document root.\n",
      " |  \n",
      " |  read(self, stream)\n",
      " |  \n",
      " |  readNextEndLine(self, stream)\n",
      " |  \n",
      " |  readObjectHeader(self, stream)\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Readonly properties defined here:\n",
      " |  \n",
      " |  documentInfo\n",
      " |  \n",
      " |  isEncrypted\n",
      " |  \n",
      " |  namedDestinations\n",
      " |  \n",
      " |  numPages\n",
      " |  \n",
      " |  outlines\n",
      " |  \n",
      " |  pageLayout\n",
      " |      Get the page layout.\n",
      " |      See :meth:`setPageLayout()<PdfFileWriter.setPageLayout>`\n",
      " |      for a description of valid layouts.\n",
      " |      \n",
      " |      :return: Page layout currently being used.\n",
      " |      :rtype: ``str``, ``None`` if not specified\n",
      " |  \n",
      " |  pageMode\n",
      " |      Get the page mode.\n",
      " |      See :meth:`setPageMode()<PdfFileWriter.setPageMode>`\n",
      " |      for a description of valid modes.\n",
      " |      \n",
      " |      :return: Page mode currently being used.\n",
      " |      :rtype: ``str``, ``None`` if not specified\n",
      " |  \n",
      " |  pages\n",
      " |  \n",
      " |  xmpMetadata\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data descriptors defined here:\n",
      " |  \n",
      " |  __dict__\n",
      " |      dictionary for instance variables (if defined)\n",
      " |  \n",
      " |  __weakref__\n",
      " |      list of weak references to the object (if defined)\n",
      "\n"
     ]
    },
    {
     "ename": "PdfReadError",
     "evalue": "File has not been decrypted",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNotImplementedError\u001b[0m                       Traceback (most recent call last)",
      "\u001b[1;32mD:\\Development\\Anaconda\\envs\\WebCrawler\\lib\\site-packages\\PyPDF2\\pdf.py\u001b[0m in \u001b[0;36mgetNumPages\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m   1146\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_override_encryption\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mTrue\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1147\u001b[1;33m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdecrypt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m''\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1148\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtrailer\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"/Root\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"/Pages\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"/Count\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\Development\\Anaconda\\envs\\WebCrawler\\lib\\site-packages\\PyPDF2\\pdf.py\u001b[0m in \u001b[0;36mdecrypt\u001b[1;34m(self, password)\u001b[0m\n\u001b[0;32m   1986\u001b[0m         \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1987\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_decrypt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpassword\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1988\u001b[0m         \u001b[1;32mfinally\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\Development\\Anaconda\\envs\\WebCrawler\\lib\\site-packages\\PyPDF2\\pdf.py\u001b[0m in \u001b[0;36m_decrypt\u001b[1;34m(self, password)\u001b[0m\n\u001b[0;32m   1995\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;33m(\u001b[0m\u001b[0mencrypt\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'/V'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;32min\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1996\u001b[1;33m             \u001b[1;32mraise\u001b[0m \u001b[0mNotImplementedError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"only algorithm code 1 and 2 are supported\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1997\u001b[0m         \u001b[0muser_password\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkey\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_authenticateUserPassword\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpassword\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNotImplementedError\u001b[0m: only algorithm code 1 and 2 are supported",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mPdfReadError\u001b[0m                              Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_7968/3746122391.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     26\u001b[0m     \u001b[0mfile_path\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34mr'C:/Users/DELL/Downloads/编写高质量代码：改善Python程序的91个建议.pdf'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     27\u001b[0m     \u001b[0msave_name\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'高质量代码.pdf'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 28\u001b[1;33m     \u001b[0mcopyPDF\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile_path\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msave_name\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_7968/3746122391.py\u001b[0m in \u001b[0;36mcopyPDF\u001b[1;34m(file_path, save_name)\u001b[0m\n\u001b[0;32m     14\u001b[0m         \u001b[1;31m# 复制文件\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     15\u001b[0m         \u001b[0moutput\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mPdfFileWriter\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 16\u001b[1;33m         \u001b[0mpages\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetPage\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minput\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgetNumPages\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     17\u001b[0m         \u001b[1;32mfor\u001b[0m \u001b[0mpage\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mpages\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     18\u001b[0m             \u001b[0moutput\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maddPage\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpage\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mD:\\Development\\Anaconda\\envs\\WebCrawler\\lib\\site-packages\\PyPDF2\\pdf.py\u001b[0m in \u001b[0;36mgetNumPages\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m   1148\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtrailer\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"/Root\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"/Pages\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"/Count\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1149\u001b[0m             \u001b[1;32mexcept\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1150\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0mutils\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mPdfReadError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"File has not been decrypted\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1151\u001b[0m             \u001b[1;32mfinally\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1152\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_override_encryption\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mFalse\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mPdfReadError\u001b[0m: File has not been decrypted"
     ]
    }
   ],
   "source": [
    "'''\n",
    "先截图pdf中的目录并用QQ来提取图片中的文字，使用VScode对\n",
    "所得目录进行处理，再提取书签和页码分别存放在bookmark.txt\n",
    "和page.txt两个文件中，二级标题前面加|，三级标签前面加||，以此类推。\n",
    "https://www.cnblogs.com/aminor/p/14590188.html\n",
    "'''\n",
    "from PyPDF2 import PdfFileReader, PdfFileWriter\n",
    "\n",
    "def copyPDF(file_path, save_name):\n",
    "\n",
    "    # 打开文件\n",
    "    with open(file_path, 'rb') as fp:\n",
    "        input = PdfFileReader(fp)\n",
    "        # 复制文件\n",
    "        output = PdfFileWriter()\n",
    "        pages = [input.getPage(i) for i in range(input.getNumPages())]\n",
    "        for page in pages:\n",
    "            output.addPage(page)\n",
    "            \n",
    "        \n",
    "    with open(save_name,'wb+') as f:\n",
    "        output.write(f)\n",
    "        \n",
    "if __name__ == \"__main__\":\n",
    "\n",
    "    file_path = r'C:/Users/DELL/Downloads/编写高质量代码：改善Python程序的91个建议.pdf'\n",
    "    save_name = '高质量代码.pdf'\n",
    "    copyPDF(file_path, save_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class Try:\n",
    "    ...\n",
    "\n",
    "a = Try()\n",
    "def get(self, key):\n",
    "    return 10 \n",
    "Try.__getitem__ = get\n",
    "a[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "x() missing 1 required positional argument: 'self'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_8416/1559304838.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      3\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[1;36m10\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      4\u001b[0m \u001b[0mt\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtest\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[0mtest\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m: x() missing 1 required positional argument: 'self'"
     ]
    }
   ],
   "source": [
    "class test:\n",
    "    def x(self):\n",
    "        return 10\n",
    "t = test()\n",
    "test.x()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0)\n"
     ]
    }
   ],
   "source": [
    "from collections.abc import Iterable\n",
    "\n",
    "class myiter():\n",
    "    def __iter__(self):\n",
    "        for i in range(10):\n",
    "            yield i\n",
    "\n",
    "issubclass(myiter, Iterable)\n",
    "\n",
    "def i():\n",
    "    ...\n",
    "import sys\n",
    "print(sys.version_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0   :  0  \n",
      "1   :  1  \n",
      "2   :  2  \n",
      "unknow:  3  \n"
     ]
    }
   ],
   "source": [
    "import itertools\n",
    "for name, country in itertools.zip_longest(range(3), range(4), fillvalue='unknow'):\n",
    "    print(f'{name:<4}:{country:^5}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NB!\n",
      "10\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(2085002807424, 2085002656768)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "if a:='fine' :\n",
    "    print('NB!')\n",
    "else:\n",
    "    print(a)\n",
    "if (b := 10) > 4:\n",
    "    print(b)\n",
    "\n",
    "# while (i:=10) > 5:\n",
    "#     print(i)\n",
    "#     i -= 1\n",
    "a = [1,2]\n",
    "# print(a.extend([[3,4]]))\n",
    "id(a[:]), id(a)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "28  35  50\n",
      "b'ci'\n"
     ]
    }
   ],
   "source": [
    "w = 'shousi'\n",
    "x = w.encode('utf-8')\n",
    "y = x[::-1]\n",
    "z = y.decode('utf-8')\n",
    "x, y\n",
    "import sys\n",
    "a = 2\n",
    "b = 'ci'.encode('utf-8')\n",
    "c = 's'\n",
    "print(f'{sys.getsizeof(a)}  {sys.getsizeof(b)}  {sys.getsizeof(c)}')\n",
    "print(b)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0, [1, 2, 3, 4, 5, 6, 7], 8)"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = range(9)\n",
    "b, *_, c = a\n",
    "b, _, c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1973649066048\n",
      "1973649066048\n",
      "1973649199424\n",
      "1973649066048\n"
     ]
    }
   ],
   "source": [
    "a = list(range(9))\n",
    "sorted(a, key = lambda x: x, reverse=True)\n",
    "print(id(a))\n",
    "a.sort(key = lambda x: -id(x))\n",
    "print(id(a))\n",
    "sorted(a, key = lambda x: id(x))\n",
    "\n",
    "a = [\n",
    "    [3, 2, 5],\n",
    "    [1, 3, 4],\n",
    "    [1, 2, 4],\n",
    "    [1, 3, 2],\n",
    "]\n",
    "print(id(a))\n",
    "for i in range(len(a[0])):\n",
    "    sort_pos = len(a[0]) - i - 1\n",
    "    a = sorted(a, key = lambda x: x[sort_pos])\n",
    "print(id(a))\n"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "304fe461dc7a51a7d37635154b9407ecc2c880777499052fc195a7e0f9e1dfee"
  },
  "kernelspec": {
   "display_name": "Python 3.9.7 ('SciencePY')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
